import request from '../../../util/request'

import { ResponseData, AttrResponseData, Attr } from './type'

// 定义接口枚举
enum API {
  // 获取一级分类
  GET_CATEGORY1 = '/admin/product/getCategory1',
  // 获取二级分类
  GET_CATEGORY2 = '/admin/product/getCategory2/',
  // 获取三级分类
  GET_CATEGORY3 = '/admin/product/getCategory3/',
  // 根据一二三级分类获取分类信息
  GET_CATEGORYINFO = '/admin/product/attrInfoList/',
  //添加或者修改已有的属性的接口
  ADDORUPDATEATTR_URL = '/admin/product/saveAttrInfo',
  // 根据id删除某个基础属性
  DELETE_ATTR = '/admin/product/deleteAttr/',
}

// 获取一级分类数据
export const reqCategory1List = () =>
  request.get<ResponseData, any>(API.GET_CATEGORY1)

//获取二级分类的接口方法
export const reqCategory2List = (category1Id: number | string) => {
  return request.get<any, any>(API.GET_CATEGORY2 + category1Id)
}

//获取三级分类的接口方法
export const reqCategory3List = (category2Id: number | string) => {
  return request.get<any, any>(API.GET_CATEGORY3 + category2Id)
}

//获取对应分类下已有的属性与属性值接口
export const reqAttr = (
  category1Id: string | number,
  category2Id: string | number,
  category3Id: string | number,
) => {
  return request.get<any, AttrResponseData>(
    API.GET_CATEGORYINFO + `${category1Id}/${category2Id}/${category3Id}`,
  )
}

//新增或者修改已有的属性接口
export const reqAddOrUpdateAttr = (data: Attr) =>
  request.post<any, any>(API.ADDORUPDATEATTR_URL, data)

// 删除某个属性的接口
export const deleteAttr = (id: number) => {
  return request.delete<any, any>(API.DELETE_ATTR + id)
}
